srs.tauhaty=function(data,x,y,n,N,taux){ data=as.name(data); x=x; y=y; n=n; N=N; taux=taux; mux=taux/N plot(x,y,main=data) r=sum(y)/sum(x); muhat.y=r*mux; tauhat.y=r*taux fpc=(1-n/N); s2r=sum((y-r*x)^2)/(n-1) vhat.r=fpc*(1/mux^2)*(s2r/n) vhat.tauhat.y=taux^2*vhat.r bound=2*sqrt(vhat.tauhat.y) lower=tauhat.y-bound; upper=tauhat.y+bound cat("","\n","Results from SRS: Data =",data,"\n",'Estimation method = Ratio for total y','\n',"N =",N,"n =",n, "\n","FPC =",fpc,"\n","Tau y =",tauhat.y,"\n","Vhat tau.y =",vhat.tauhat.y,"\n","Bound =",bound,"\n", "Lower Bound =",lower,"Upper Bound =",upper,"\n","") results=list(r=r,data=data,n=n,N=N,fpc=fpc,vhat.r=vhat.r,s2r=s2r,bound=bound,lower=lower,upper=upper) } # to use the function with its call: # srs.tauhaty(data,x,y,n,N,taux) # data: name of dataset, in quotes # x: vector (data) # y: vector (data) # n: sample size # N: population size # taux: value of total of X; if taux is unknown, use taux=N*mux. # If taux and mux are unknown, use mux=xbar and taux=N*xbar